<!DOCTYPE html>
<html>

<head>
	<meta charset="utf-8">
	<title>签到上墙</title>
	<meta name="viewport"
		content="width=device-width,initial-scale=1,minimum-scale=1,maximum-scale=1,user-scalable=no,viewport-fit=cover" />
	<link rel="stylesheet" href="css/wxQian.css">
	<link rel="stylesheet" href="./css/vant.css">
	<style>
		.tianimg {
			left: 4.1333rem;
			width: 1.7333rem;
			height: 1.6267rem;
		}
	</style>
</head>

<body>
	<div id="app" v-clock>
		<div class="box">
			<div class="imgbox">
				<img src="./img/title.png">
				<img src="./img/finfis.png">
			</div>
			<div class="formBox">
				<div v-if="nameFlag">
					<span>姓名</span>
					<input type="text" v-model="name" @focus="isShowLogo=false" @blur="isShowLogo=true"
						placeholder="请输入姓名">
				</div>
				<div v-if="telFlag">
					<span>手机号</span>
					<input type="number" v-model="tel" placeholder="请输入手机号" @focus="isShowLogo=false"
						@blur="isShowLogo=true">
				</div>
				<div v-if="sexFlag">
					<span>身份</span>
					<van-radio-group v-model="sex" direction="horizontal">
						<van-radio name="医生">医生</van-radio>
						<van-radio name="经理">经理</van-radio>
					</van-radio-group>
				</div>
				<div v-if="companyFlag">
					<span>单位</span>
					<input type="text" v-model="company" placeholder="请输入单位名称" @focus="isShowLogo=false"
						@blur="isShowLogo=true">
				</div>
				<div v-if="positionFlag">
					<span>地区</span>
					<input type="text" v-model="position" placeholder="请选择地区" readonly @click="addressDialog=true">
				</div>
			</div>
			<div @click="toSubmit" class="subBtn"></div>
			<img src="./img/zbzLogo.png" class="aiimg" v-if="systemId!=2&&isShowLogo">
			<img src="./img/tianBg.png" class="tianimg aiimg" v-if="systemId==2&&isShowLogo">

			<div class="loading" v-show="isShow">
				<img src="img/load.gif">
			</div>
		</div>

		<van-popup v-model="addressDialog" round position="bottom">
			<van-cascader v-model="cityValue" title="请选择城市" :options="cityData3" @close="addressDialog = false"
				@finish="onFinish" />
		</van-popup>



	</div>
	<script src="js/vue.min.js"></script>
	<script src="js/flex_ible/lib-flexible.js"></script>
	<script src="js/url.js"></script>
	<script src="js/vant.min.js"></script>
	<script src="js/city.data-3.js"></script>
	<script src="js/ajax.js" type="text/javascript" charset="utf-8"></script>
	<script type="text/javascript">


		function GetQueryString(name) {
			var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)");
			var r = window.location.search.substr(1).match(reg);
			if (r != null) return unescape(r[2]);
			return null;
		}

		var activeId = sessionStorage.activeId
		console.log(activeId);

		var app = new Vue({
			el: '#app',
			data: {
				name: '',
				tel: '',
				sex: '',
				singFlag: 0,
				company: '',
				position: '',
				isShow: false,
				activeInfo: '',
				formList: '',
				nameFlag: true,
				telFlag: true,
				sexFlag: true,
				companyFlag: true,
				positionFlag: true,
				isSign: false,
				isShowLogo: true,//是否显示logo
				addressDialog: false,// 选择地址
				// 城市信息
				cityValue: '',
				userAddress: '',
				systemId: ''
			},
			methods: {
				onFinish(obj) {
					var that = this;
					console.log(obj);
					var arr = []
					obj.selectedOptions.forEach(item => {
						arr.push(item.text)
						that.position = arr.join('/')
					})
					console.log(arr);
					this.addressDialog = false
				},

				getData() {
					var that = this
					ajax({
						url: "https://www.ccclkj.cn:2033/signature/getSignature",
						// url: "http://192.168.0.101:2033/signature/getSignature",
						type: 'post',
						data: {},
						dataType: 'json',
						timeout: 10000,
						contentType: "application/json",
						success: function (res) {
							var res = JSON.parse(res)
							console.log(res);
							if (res.flag) {
								that.activeInfo = res.data.filter(item => {
									return item.signatureId == activeId
								})[0];
								console.log(that.activeInfo);


								that.systemId = that.activeInfo.signatureNote

								that.isSign = localStorage.singFlag == "s_" + that.activeInfo.signatureId
								console.log(that.isSign);

								if (that.isSign) {
									alert('您已签到，请勿重复签到')
								}
								console.log(that.activeInfo);
								that.formList = that.activeInfo.signatureFlag
								console.log(that.formList);
								that.telFlag = that.formList.indexOf('电话') != -1
								that.sexFlag = that.formList.indexOf('身份') != -1
								that.companyFlag = that.formList.indexOf('单位') != -1
								that.positionFlag = that.formList.indexOf('地区') != -1
							}
						},
					})
				},
				toSubmit: function () {
					if (this.isSign) {
						alert('您已签到，请勿重复签到')
						return
					}
					if (this.name == '' && this.nameFlag) {
						alert('请输入姓名')
						return
					} else if (!this.checkText(this.name)) {
						alert('姓名应为纯中文字符')
						return
					} else if (this.tel == '' && this.telFlag) {
						alert('请输入手机号')
						return
					} else if (!this.validator(this.tel)) {
						alert('请输入正确的手机号')
						return
					} else if (this.sex == '' && this.sexFlag) {
						alert('请选择身份')
						return
					} else if (this.company == '' && this.companyFlag) {
						alert('请输入单位名称')
						return
					} else if (this.position == '' && this.positionFlag) {
						alert('请选择地区')
						return
					}
					console.log(this.name);
					console.log(this.tel);
					console.log(this.sex);
					var _this = this;
					this.isShow = true
					ajax({
						url: "https://www.ccclkj.cn:2033/client/toSign",
						// url: "http://192.168.0.101:2033/client/toSign",
						type: 'post',
						data: {
							name: _this.name,
							tel: _this.tel,
							sex: _this.sex,
							classId: 's_' + _this.activeInfo.signatureId,
							company: _this.company,
							position: _this.position,
						},
						dataType: 'json',
						timeout: 10000,
						contentType: "application/json",
						success: function (res) {
							var res = JSON.parse(res)
							console.log(res);
							if (res.data == "success") {
								_this.isShow = false
								_this.isSign = true
								alert('签到成功')
								_this.addSignList()
								localStorage.singFlag = "s_" + _this.activeInfo.signatureId
							} else if (res.data == "error") {
								_this.isShow = false
								alert('签到通道已关闭，不可签到')
							}
						},
					})
				},

				addSignList() {
					var _this = this;
					ajax({
						url: "https://www.ccclkj.cn:2028/meeting/addAndEditCheckSignin",
						// url: "http://192.168.0.112:2028/meeting/addAndEditCheckSignin",
						type: 'post',
						data: {
							name: _this.name,
							phone: _this.tel,
							identitys: _this.sex,
							clinique: _this.company,
							province: _this.position.split('/')[0],
							city: _this.position.split('/')[1] || '',
							area: _this.position.split('/')[2] || '',
							spare4: _this.systemId
						},
						dataType: 'json',
						timeout: 10000,
						contentType: "application/json",
						success: function (res) {
							var res = JSON.parse(res)
							console.log(res);

						},
					})

				},
				validator: function (val) {
					return /^(?:(?:\+|00)86)?1(?:(?:3[\d])|(?:4[5-79])|(?:5[0-35-9])|(?:6[5-7])|(?:7[0-8])|(?:8[\d])|(?:9[189]))\d{8}$/.test(val) || /^(?:(?:\d{3}-)?\d{8}|^(?:\d{4}-)?\d{7,8})(?:-\d+)?$/.test(val);
				},

				checkText(str) {
					var reg = new RegExp("[\\u4E00-\\u9FFF]+", "g")
					if (!reg.test(str)) {
						return false;
					} else {
						return true;
					}
				},

				getNowTime() {
					var myDate = new Date();
					var Y = myDate.getFullYear();
					var M = myDate.getMonth() + 1;
					var D = myDate.getDate();
					var H = myDate.getHours();
					var i = myDate.getMinutes();
					var s = myDate.getSeconds();
					if (M < 10) {
						M = "0" + M;
					}
					if (D < 10) {
						D = "0" + D;
					}
					if (H < 10) {
						H = "0" + H;
					}
					if (i < 10) {
						i = "0" + i;
					}
					if (s < 10) {
						s = "0" + s;
					}
					return Y + "-" + M + "-" + D + " " + H + ":" + i + ":" + s;
				}
			},
			created: function () {


				this.getData()
				// if (localStorage.singFlag == "s_" + activeId) {
				// 	alert('您已签到，请勿重复签到')
				// }
			}
		})
	</script>
</body>

</html>